home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Tech Arsenal 1
/
Tech Arsenal (Arsenal Computer).ISO
/
tek-01
/
lcppb.zip
/
LCPPANS.ZIP
/
WORDS2.CPP
< prev
Wrap
C/C++ Source or Header
|
1991-07-08
|
829b
|
41 lines
// words2.cpp -- Count words in standard input
#include <iostream.h>
#include <ctype.h>
#include <stdio.h>
main()
{
char c;
int words, chars, lines, insideWord;
words = chars = lines = insideWord = 0;
while ((c = getchar()) != EOF) {
chars++;
if (c == '\n') {
lines++;
chars++;
}
if (!isspace(c)) {
if (!insideWord) {
insideWord = 1; // True
words++;
}
} else
insideWord = 0; // False
}
cout << chars << " total character(s)\n";
cout << words << " word(s)\n";
cout << lines << " line(s)\n";
}
// Copyright (c) 1990 by Tom Swan. All rights reserved
// Revision 1.00 Date: 10/24/1990 Time: 08:17 am
// Revision 1.01 Date: 07/08/1991 Time: 05:41 pm
// Converted for Borland C++ 2.0